$(function() {
	$('#vue_vm_list div').hide();
});

var retreatLease = {
	retreatLeaseId: '',
	suppliesName: '',
	brand: '',
	model: '',
	price: '',
	cashPledge: '',
	rent: '',
	iconUrl: '',
	intro: '',
	leaseNumber: '',
	disinfectStatus: '',
	createTime: '',
	updateTime: '',
	createId: getLoginedUser()? getLoginedUser().staffId: '',
	updateId: getLoginedUser()? getLoginedUser().staffId: '',
	remark: '',
	leaseSuppliesId: '',
	elderId: '',
	status: '',
};

findAll();

function findAll() {
	if($('#vue_vm_list').length==0) {return;}
	$('#vue_vm_list div').hide();

	findAll_basic(path+'/retreatLease/findAll', function(response) {
		$('#vue_vm_list').html(gl_vue_vm_list_html);
		
		new Vue({
			el: '#vue_vm_list',
			data: {
				todos: response.data
			},
			methods: {
				deleteBatchById: function(leaseSuppliesId) {
					var itemIdArray = [leaseSuppliesId];
					
					deleteBatch_basic_by_array(path+'/leaseSupplies/deleteBatch', itemIdArray, function(response) {
						$('#'+leaseSuppliesId).remove();
					});
				},
				getImageFullPath: function(iconUrl) {
					return imagePath + '/' + iconUrl;
				},
				save: function(todo) {
					var disinfectStatus = $('#'+todo.retreatLeaseId+'_disinfectStatus').val();
					if(disinfectStatus=='未消毒') {
						alert('未消毒不可上架，如果确认已经消毒，请选择已消毒再上架。');
						return;
					}
					
					if(confirm('确认已经消毒吗？')) {
						todo.disinfectStatus = disinfectStatus; //重新赋值给todo的属性的这段代码，必须放在询问条件(confirm)中，以免提前引起页面标签的变化。
						todo.createTime = '';
						todo.updateTime = '';
						todo.price = (todo.price==''? 0: parseFloat(todo.price));
						todo.cashPledge = (todo.cashPledge==''? 0: parseFloat(todo.cashPledge));
						todo.rent = (todo.rent==''? 0: parseFloat(todo.rent));
						todo.leaseNumber = (todo.leaseNumber==''? 0: parseInt(todo.leaseNumber));
						todo.status = (todo.status==''? 0: parseInt(todo.status));
						
						save_basic(path+'/retreatLease/save', {retreatLease:todo}, function() {
							$('#'+todo.retreatLeaseId+'_button').remove();
							alert('上架成功');
						});
					}
				}
			}
		});
		
		$('#vue_vm_list div').show();
	});
}

function deleteBatch() {
	deleteBatch_basic(path+'/retreatLease/deleteBatch');
}
